﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;

namespace AutocompleteDemo
{
    [System.Runtime.InteropServices.Guid("B4705432-D0B2-4999-B23B-CD0A116DD8F4")]
    public sealed class AutoCompletionServiceInstance : SPIisWebServiceInstance
	{
        public AutoCompletionServiceInstance()
        {
        }

        internal AutoCompletionServiceInstance(SPServer server, AutoCompletionService service)
            : base(server, service)
        {
        }

        internal AutoCompletionServiceInstance(string name, SPServer server, AutoCompletionService service)
            : base(server, service)
        {
        }

        public override string DisplayName
        {
            get { return "AutoCompletionServiceInstance"; }
        }

        public override string TypeName
        {
            get { return "AutoCompletionServiceInstance"; }
        }

        internal bool IsLocal
        {
            get
            {
                SPServer local = SPServer.Local;
                SPServer server = base.Server;
                return ((local != null) && (local.Id == server.Id));
            }
        }

        internal static bool IsLocalInstanceOnline
        {
            get
            {
                bool flag2;
                try
                {
                    bool flag = false;
                    SPServer local = SPServer.Local;
                    if (local != null)
                    {
                        AutoCompletionServiceInstance instance = local.ServiceInstances.GetValue<AutoCompletionServiceInstance>();
                        if (instance != null)
                        {
                            flag = instance.Status == SPObjectStatus.Online;
                        }
                    }
                    flag2 = flag;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return flag2;
            }
        }

        internal bool IsOnline
        {
            get
            {
                return (base.Status == SPObjectStatus.Online);
            }
        }

        internal static AutoCompletionServiceInstance Local
        {
            get
            {
                SPServer local = SPServer.Local;
                if (local == null)
                {
                    throw new InvalidOperationException("AutoCompletionServiceInstance.Local:Failed to obtain local server.");
                }
                return local.ServiceInstances.GetValue<AutoCompletionServiceInstance>();
            }
        }
	}
}
